package com.abbas.test230430;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;

import com.abbas.test230430.databinding.ActivityMainBinding;
import com.abbas.test230430.entity.TransactionEntity;
import com.abbas.test230430.view.TransactionTableLayout;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMainBinding mainBinding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(mainBinding.getRoot());


        ArrayList<TransactionEntity> transactionEntities = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            transactionEntities.add(new TransactionEntity(i, 120, 120, 120));
        }
        mainBinding.table.addRows(transactionEntities);

        mainBinding.table.setListener(new TransactionTableLayout.OnItemSettingClickListener() {
            @Override
            public void onClick(int position, TransactionEntity data) {
                Toast.makeText(MainActivity.this, String.valueOf(position), Toast.LENGTH_LONG).show();
            }
        });
        String[] spinnerArray = getResources().getStringArray(R.array.spinner);

        mainBinding.spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                mainBinding.table.sort(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }
}